package com.heima.wemedia.dealy;

import com.heima.common.delayTask.RedisDelayQueueHandler;
import com.heima.wemedia.entity.WmNews;
import com.heima.wemedia.service.WmNewsAuditService;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 执行延迟 任务的实现类
 */
@Slf4j
@Service
public class PublicNewsDelayHandler implements RedisDelayQueueHandler {

    @Autowired
    private WmNewsAuditService wmNewsAuditService;
    @Autowired
    private WmNewsService wmNewsService;
    /**
     * 获取到延迟的 任务内容
     * 文章id ，
     * 发布当前的文章
     * @param o
     */
    @Override
    public void execute(Object o) {
        log.info("从延迟队列获取到数据o={}",o);
        Integer wmNewsId = Integer.valueOf(o.toString());
        if(wmNewsId.intValue() == 0){
            log.info("无用数据，直接返回！");
            return ;
        }
        log.info("从延迟队列获取到数据 wmNewsId={}",wmNewsId);
        WmNews wmNews = wmNewsService.getById(wmNewsId);
        log.info("从延迟队列获取到数据 wmNews={}",wmNews);
        wmNewsAuditService.pubWmNews(wmNews);
    }
}
